﻿using System;
using System.Collections.Generic;
using System.Linq;
using Resn.WhuPub.BLL;
using Resn.WhuPub.DAL;
using Resn.WhuPub.DML;

namespace Resn.WhuPub.BLL
{
        /// <summary>
        /// 实现经销商的属性和方法
        /// </summary>
        public class Dealer : Entity<DealerModel>
        {
                #region 构造函数

                /// <summary>
                /// Initializes a new instance of the <see cref="Dealer"/> class.
                /// </summary>
                /// <param name="model">The model.</param>
                public Dealer(DealerModel model)
                        : base(model)
                {
                }

                #endregion


                #region 属性

                #region 基本属性

                

                /// <summary>
                /// 获取或设置名称
                /// </summary>
                /// <value>
                /// 名称
                /// </value>
                public string Name
                {
                        get
                        {
                                return Model.Name;
                        }
                        set
                        {
                                Model.Name = value;
                        }
                }

                /// <summary>
                /// 获取或设置省份
                /// </summary>
                /// <value>
                /// 省份
                /// </value>
                public string Province
                {
                        get
                        {
                                return Model.Province;
                        }
                        set
                        {
                                Model.Province = value;
                        }
                }

                /// <summary>
                /// 获取或设置城市
                /// </summary>
                /// <value>
                /// 城市
                /// </value>
                public string City
                {
                        get
                        {
                                return Model.City;
                        }
                        set
                        {
                                Model.City = value;
                        }
                }

                /// <summary>
                /// 获取或设置邮编
                /// </summary>
                /// <value>
                /// 邮编
                /// </value>
                public string Postcode
                {
                        get
                        {
                                return Model.Postcode;
                        }
                        set
                        {
                                Model.Postcode = value;
                        }
                }

                /// <summary>
                /// 获取或设置注册地址
                /// </summary>
                /// <value>
                /// 注册地址
                /// </value>
                public string RegisterAddress
                {
                        get
                        {
                                return Model.RegisterAddress;
                        }
                        set
                        {
                                Model.RegisterAddress = value;
                        }
                }

                /// <summary>
                /// 获取或设置经营地址
                /// </summary>
                /// <value>
                /// 经营地址
                /// </value>
                public string BusinessAddress
                {
                        get
                        {
                                return Model.BusinessAddress;
                        }
                        set
                        {
                                Model.BusinessAddress = value;
                        }
                }

                /// <summary>
                /// 获取或设置主营业务
                /// </summary>
                /// <value>
                /// 主营业务
                /// </value>
                public string MainBusiness
                {
                        get
                        {
                                return Model.MainBusiness;
                        }
                        set
                        {
                                Model.MainBusiness = value;
                        }
                }

                /// <summary>
                /// 获取或设置联系人姓名
                /// </summary>
                /// <value>
                /// 联系人姓名
                /// </value>
                public string ContactName
                {
                        get
                        {
                                return Model.ContactName;
                        }
                        set
                        {
                                Model.ContactName = value;
                        }
                }

                /// <summary>
                /// 获取或设置联系人电话
                /// </summary>
                /// <value>
                /// 联系人电话
                /// </value>
                public string ContactTelephone
                {
                        get
                        {
                                return Model.ContactTelephone;
                        }
                        set
                        {
                                Model.ContactTelephone = value;
                        }
                }

                /// <summary>
                /// 获取或设置联系人传真
                /// </summary>
                /// <value>
                /// 联系人传真
                /// </value>
                public string ContactFax
                {
                        get
                        {
                                return Model.ContactFax;
                        }
                        set
                        {
                                Model.ContactFax = value;
                        }
                }

                /// <summary>
                /// 获取或设置联系人电子邮箱
                /// </summary>
                /// <value>
                /// 联系人电子邮箱
                /// </value>
                public string ContactEmail
                {
                        get
                        {
                                return Model.ContactEmail;
                        }
                        set
                        {
                                Model.ContactEmail = value;
                        }
                }

                /// <summary>
                /// 获取或设置法人姓名
                /// </summary>
                /// <value>
                /// 法人姓名
                /// </value>
                public string LegalName
                {
                        get
                        {
                                return Model.LegalName;
                        }
                        set
                        {
                                Model.LegalName = value;
                        }
                }

                /// <summary>
                /// 获取或设置法人电话
                /// </summary>
                /// <value>
                /// 法人电话
                /// </value>
                public string LegalTelephone
                {
                        get
                        {
                                return Model.LegalTelephone;
                        }
                        set
                        {
                                Model.LegalTelephone = value;
                        }
                }

                /// <summary>
                /// 获取或设置经理姓名
                /// </summary>
                /// <value>
                /// 经理姓名
                /// </value>
                public string ManagerName
                {
                        get
                        {
                                return Model.ManagerName;
                        }
                        set
                        {
                                Model.ManagerName = value;
                        }
                }

                /// <summary>
                /// 获取或设置经理联系电话
                /// </summary>
                /// <value>
                /// 经理联系电话
                /// </value>
                public string ManagerTelephone
                {
                        get
                        {
                                return Model.ManagerTelephone;
                        }
                        set
                        {
                                Model.ManagerTelephone = value;
                        }
                }

                /// <summary>
                /// 获取或设置财务姓名
                /// </summary>
                /// <value>
                /// 财务姓名
                /// </value>
                public string FinanceName
                {
                        get
                        {
                                return Model.FinanceName;
                        }
                        set
                        {
                                Model.FinanceName = value;
                        }
                }
                /// <summary>
                /// 获取或设置经理姓名财务联系电话
                /// </summary>
                /// <value>
                /// 财务联系电话
                /// </value>
                public string FinanceTelephone
                {
                        get
                        {
                                return Model.FinanceTelephone;
                        }
                        set
                        {
                                Model.FinanceTelephone = value;
                        }
                }

                /// <summary>
                /// 获取或设置收货人姓名
                /// </summary>
                /// <value>
                /// 收货人姓名
                /// </value>
                public string ConsigneeName
                {
                        get
                        {
                                return Model.ConsigneeName;
                        }
                        set
                        {
                                Model.ConsigneeName = value;
                        }
                }

                /// <summary>
                /// 获取或设置收货人联系电话
                /// </summary>
                /// <value>
                /// 收货人联系电话
                /// </value>
                public string ConsigneeTelephone
                {
                        get
                        {
                                return Model.ConsigneeTelephone;
                        }
                        set
                        {
                                Model.ConsigneeTelephone = value;
                        }
                }

                /// <summary>
                /// 获取或设置收货地址
                /// </summary>
                /// <value>
                /// 收货地址
                /// </value>
                public string ConsigneeAddress
                {
                        get
                        {
                                return Model.ConsigneeAddress;
                        }
                        set
                        {
                                Model.ConsigneeAddress = value;
                        }
                }

                /// <summary>
                /// 获取或设置税票户名
                /// </summary>
                /// <value>
                /// 税票户名
                /// </value>
                public string TaxName
                {
                        get
                        {
                                return Model.TaxName;
                        }
                        set
                        {
                                Model.TaxName = value;
                        }
                }

                /// <summary>
                /// 获取或设置税票账号
                /// </summary>
                /// <value>
                /// 税票账号
                /// </value>
                public string TaxAccount
                {
                        get
                        {
                                return Model.TaxAccount;
                        }
                        set
                        {
                                Model.TaxAccount = value;
                        }
                }

                /// <summary>
                /// 获取或设置税票联系电话
                /// </summary>
                /// <value>
                /// 经理姓名
                /// </value>
                public string TaxTelephone
                {
                        get
                        {
                                return Model.TaxTelephone;
                        }
                        set
                        {
                                Model.TaxTelephone = value;
                        }
                }

                /// <summary>
                /// 获取或设置税票地址
                /// </summary>
                /// <value>
                /// 税票地址
                /// </value>
                public string TaxAddress
                {
                        get
                        {
                                return Model.TaxAddress;
                        }
                        set
                        {
                                Model.TaxAddress = value;
                        }
                }

                /// <summary>
                /// 获取或设置开户行
                /// </summary>
                /// <value>
                /// 开户行
                /// </value>
                public string BankName
                {
                        get
                        {
                                return Model.BankName;
                        }
                        set
                        {
                                Model.BankName = value;
                        }
                }

                /// <summary>
                /// 获取或设置开户行账号
                /// </summary>
                /// <value>
                /// 开户行账号
                /// </value>
                public string BankAccount
                {
                        get
                        {
                                return Model.BankAccount;
                        }
                        set
                        {
                                Model.BankAccount = value;
                        }
                }

                #endregion 基本属性

                /// <summary>
                /// 获取经销商的票据寄送流程集合
                /// </summary>
                /// <value>
                /// 经销商的票据寄送流程集合
                /// </value>
                public List<InvoiceFlow> InvoiceFlows
                {
                        get
                        {
                                var models = DBStorage.Instance.Select<InvoiceFlowModel>().Where(i => i.DealerId == Id).ToList();

                                var result = new List<InvoiceFlow>();

                                models.ForEach(i => result.Add(new InvoiceFlow(i)));

                                return result;
                        }
                }
                
                #endregion 属性

                #region 方法

                /// <summary>
                /// 获取指定标识的对象
                /// </summary>
                /// <param name="id">标识</param>
                /// <returns></returns>
                public static Dealer Select(string id)
                {
                        return Select<Dealer>(id);
                }

                /// <summary>
                /// 创建经销商
                /// </summary>
                /// <param name="name">名称</param>
                /// <param name="province">省份</param>
                /// <param name="city">城市</param>
                /// <param name="Postcode">邮编</param>
                /// <param name="registerAddress">注册地址</param>
                /// <param name="businessAddress">经营地址</param>
                /// <param name="contactName">联系人姓名</param>
                /// <param name="contactTelephone">联系人电话</param>
                /// <param name="contactFax">联系人传真</param>
                /// <param name="contactEmail">联系人电子邮箱</param>
                /// <returns>
                /// 返回创建的经销商对象
                /// </returns>
                public static Dealer CreateDealer(string name, string province, string city, string Postcode, string registerAddress,
                                            string businessAddress, string contactName, string contactTelephone, string contactFax,
                                            string contactEmail)
                {
                        var model = new DealerModel
                        {
                                Id = Guid.NewGuid().ToString(),
                                Name = name,
                                Province = province,
                                City = city,
                                Postcode = Postcode,
                                RegisterAddress = registerAddress,
                                BusinessAddress = businessAddress,
                                ContactName = contactName,
                                ContactTelephone = contactTelephone,
                                ContactFax = contactFax,
                                ContactEmail = contactEmail
                        };

                        return new Dealer(model);
                }

                /// <summary>
                /// 创建发票寄送流程流程
                /// </summary>
                /// <param name="billingEmployeeId">开票员工标识</param>
                /// <param name="billingNumber">开票号</param>
                /// <param name="billingTime">开票时间</param>
                /// <param name="billingAmount">开票金额</param>
                /// <param name="deliveryNumber">寄送单号</param>
                /// <param name="deliveryTime">寄送时间</param>
                /// <returns>
                /// 创建的发票寄送流程流程对象
                /// </returns>
                /// <exception cref="System.NotImplementedException"></exception>
                public InvoiceFlow CreateInvoice(string billingEmployeeId, string billingNumber, string billingTime,
                                                                          double billingAmount, string deliveryNumber, DateTime deliveryTime)
                {
                        var model = new InvoiceFlowModel
                                {
                                        Id = Guid.NewGuid().ToString(),
                                        BillingEmployeeId = billingEmployeeId,
                                        BillingNumber = billingNumber,
                                        BillingTime = billingTime,
                                        BillingAmount = billingAmount,
                                        DeliveryNumber = deliveryNumber,
                                        DeliveryTime = deliveryTime
                                };

                        return new InvoiceFlow(model);
                }

                
                #endregion

        }
}